/*
 * Lib.h
 *
 *  Created on: May 27, 2009
 *      Author: ruslan
 */

#ifndef LIB_H_
#define LIB_H_

#include <string>
#include <list>
#include <sys/time.h>

using namespace std;


class Lib {
	public:
		// Schedule
		static string htmlRepresentOfSchedule(int***, int, int, int, list<int*>, string topText, string bottomText);
		static list<int*> checkSchedule (int***, int, int, int, int, int, int);
		// Time
		static long getTimeDiffInMilliseconds (timeval, timeval);
		static string formatTimeInMilliseconds(long);

		static void getTimeDiffInMilliseconds(string&, string&, bool);

		static void deleteValueofPointersToArrInList(list<int*> l);

		template <class T> static T*** makeCopyOfMtrx3(T*** mtrx3Int, int i, int j, int k) {
			 T*** newMtrx3 = new T**[i];
			 for (int ii=0; ii<i ; ii++) {
				 newMtrx3[ii] = new T*[j];
				 for (int jj=0; jj<j ; jj++) {
					 newMtrx3[ii][jj] = new T[k];
					 for (int kk=0; kk<k ; kk++)
						 newMtrx3[ii][jj][kk] = mtrx3Int[ii][jj][kk];
				 }
			 }
			 return newMtrx3;
		 }


		 template <class T> static void deleteMatrix(T** mtrx, int i) {
			 for (int i2=0; i2<i; i2++)
					 delete [] mtrx[i2];
			 delete [] mtrx;
		 }

		 template <class T> static void deleteMatrix3(T*** mtrx, int i, int j) {
			 for (int ii=0; ii<i; ii++) {
				 for (int jj=0; jj<j; jj++) {
					 delete [] mtrx[ii][jj];
				 }
				 delete [] mtrx[ii];
			 }
			 delete [] mtrx;
		 }

		 template <class T> static void deleteMatrix4(T**** mtrx, int i, int j, int k) {
			 for (int ii=0; ii<i; ii++) {
				 for (int jj=0; jj<j; jj++) {
					 for (int kk=0; kk<k; kk++) {
						 delete [] mtrx[ii][jj][kk];
					 }
					 delete [] mtrx[ii][jj];
				 }
				 delete [] mtrx[ii];
			 }
			 delete [] mtrx;
		 }

		 template <class T> static void setValueInArr(T* arr, int i, T val) {
			 for (int i2=0; i2<i; i2++)
					 arr[i2] = val;
		 }

		 static string getMtrx3AsString(string name, int*** mtrx3, int n, int m, int l);
		 static string getMtrxGamesAsString(int** mtrxGames, int playersCnt);
		 static string getMtrx4TabuAsString(int**** mtrx4Tabu, int WEEKS, int playersCnt);
		 static string getMtrxConflictIndecesAsString(list<int>** arrConflictIndeces, int WEEKS, int GROUPS_IN_WEEK);

};


#endif /* LIB_H_ */
